home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / appkit.677 < prev    next >
Text File  |  1992-02-06  |  2KB  |  55 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f3\fmodern Courier;\f1\fswiss Helvetica;}
  2. \paperw11440
  3. \paperh9000
  4. \margl120
  5. \margr120
  6. {\colortbl\red0\green0\blue0;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ul0\fs28     \
  8. Q:  The 2.0 Appkit Release Notes mention that you can use the 
  9. \f3\fs24 pasteFont:
  10. \f0\fs28  method of the Text object as a “low-pain” method for extracting font information from the Font Pasteboard.  Trouble is, when I try to do this, I always get the default font information -- Helvetica 12pt.  What am I doing wrong?\
  11.  
  12. \i     \
  13.  
  14. \i0 A:  The solution is easy but perhaps not obvious.  In order for the paste operation to have any effect, the Text object must contain a selection.  It is not even strictly necessary that it contain any text.  The following code illustrates the “low-pain” method of extracting font values from the Pasteboard.  [The alternative “high-pain” method would involve parsing the rich text format from the Pasteboard]:\
  15. \
  16. \
  17.  
  18. \pard\tx620\tx1240\tx1860\tx2480\tx3100\tx3720\tx4340\tx4980\tx5600\tx6220\f3\fs24\fc0 #import <appkit/Text.h>\
  19. #import <appkit/Font.h>\
  20. \
  21.     \
  22.     id    font, myText;\
  23.     \
  24.     /* Allocate a temporary Text object */\
  25.     myText = [[Text alloc] init];\
  26.     \
  27.     /* It must allow multiple fonts -- ie. rich text */\
  28.     [myText setMonoFont: NO];\
  29.     \
  30.     /* Stick in some text -- optional */\
  31.     [myText setText:"hello"];\
  32.     \
  33.     /* And select it -- any selection will do so long */\
  34.     /* as something is selected */\
  35.     [myText setSel:0  :1];\
  36.         \
  37.     /* pasteFont: will copy the font info from the Pasteboard\
  38.     /* to the font in the Text object */\
  39.     [myText pasteFont:sender];\
  40.     \
  41.     /* Do what you need to with the font */\
  42.     font = [myText font];\
  43.     \
  44.     /* Then free up the Text object */\
  45.     [myText free];\
  46.  
  47. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\fs28 \
  48. \
  49. QA677\
  50. \
  51. Not valid for 1.0\
  52. Valid for 2.0                \
  53. \
  54.  
  55.